package com.dc.seckill.controller;

import com.dc.seckill.result.Result;
import com.dc.seckill.service.MiaoshaUserService;
import com.dc.seckill.vo.LoginVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @模块 用户模块
 * @作者 djs
 * @时间 2018/3/19 9:09
 * @版本 V1.0
 * @描述 用户进行登录等操作
 */
@Controller
@RequestMapping("/login")
public class LoginController {

    private Logger log = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private MiaoshaUserService userService;

    /**
     * 跳转登录页面
     * @params []
     * @returns java.lang.String
     */
    @RequestMapping("/to_login")
    public String toLogin(){
        return "login";
    }

    /**
     * 进行登录
     * @params [loginVo]
     * @returns com.dc.seckill.result.Result<java.lang.Boolean>
     */
    @RequestMapping("/do_login")
    @ResponseBody
    public Result<Boolean> doLogin(HttpServletResponse response, @Valid LoginVo loginVo){
        log.info("开始请求登录:"+loginVo.toString());

        userService.login(response,loginVo);

        return Result.success(true);

    }

}
